#include("layout.html")
#@layout()
#define content()
<form class=" form-setting"
      action="#(CPATH)/install/gotoStep3" method="post" id="form">
    <div class="form-group row">
        <div class="col-sm-12">
            请填写数据库的相关信息。
        </div>
    </div>
    <h4 class="form-header" style="margin-top: 20px"></h4>
    <div class="form-group row">
        <label class="col-sm-2 col-form-label">数据库名</label>
        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="您要将JPress安装到哪个数据库？"
                   name="dbName" value="#(JPRESS_DB_NAME ??)">
            <p class="text-muted"> 注意：目前暂时只支持 mysql 5.6 或 5.7 版本。 </p>
        </div>
    </div>
    <div class="form-group row">
        <label class="col-sm-2 col-form-label">用户名</label>

        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="数据库用户名"
                   name="dbUser" value="#(JPRESS_DB_USER ??)">
        </div>
    </div>

    <div class="form-group row">
        <label class="col-sm-2 col-form-label">密码</label>

        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="... 及密码"
                   name="dbPwd" value="#(JPRESS_DB_PASSWORD ??)">
        </div>
    </div>

    <div class="form-group row">
        <div class="offset-sm-2 col-sm-10">
            <label>
                <input type="checkbox" name="dbAutoCreate" value="true"> 当数据库不存在时，自动为我创建（需要用户拥有相关权限）。
            </label>
        </div>
    </div>


    <h4 class="form-header">主机信息</h4>

    <div class="form-group row">
        <label class="col-sm-2 col-form-label">主机</label>
        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="主机或IP地址"
                   name="dbHost" value="#(JPRESS_DB_HOST ?? '127.0.0.1')">
            <p class="text-muted">如果 127.0.0.1 不能用，您通常可以从网站服务商得到正确的信息。</p>
        </div>
    </div>
    <div class="form-group row">
        <label class="col-sm-2 col-form-label">端口号</label>
        <div class="col-sm-9">
            <input type="text" class="form-control" placeholder="数据库端口号"
                   name="dbPort" value="#(JPRESS_DB_PORT ?? '3306')">
            <p class="text-muted">MySQL 的默认端口号是 3306 。</p>
        </div>
    </div>

    <div class="row">
        <div class=" col-xs-3 " style="padding-top: 15px">
            <a href="#(CPATH)/install" class="btn btn-default btn-block btn-flat"> 上一步 </a>
        </div>

        <div class="col-xs-offset-6 col-xs-3 " style="padding-top: 15px">
            <button type="button" id="submit" class="btn btn-primary btn-block btn-flat"> 下一步</button>
        </div>
    </div>
</form>
#end

#define script()
<script src="#(CPATH)/static/components/jquery/jquery.min.js"></script>
<script src="#(CPATH)/static/components/jquery/jquery.form.min.js"></script>
<script src="#(CPATH)/static/components/bootstrap/js/bootstrap.min.js"></script>
<script>

    $("#submit").on("click", function () {
        $("#form").ajaxSubmit({
            type: "post",
            success: function (data) {
                if (data.state == "ok") {
                    location.href = "#(CPATH)/install/step3";
                } else if (data.errorCode) {
                    alert(data.message)
                } else {
                    location.href = "#(CPATH)/install/error";
                }

            },
            error: function () {
                alert("系统错误，请联系管理员。");
            }
        });
    })
</script>
#end
